// src/api/coach/index.ts
import {adminRequest, userRequest} from "@/utils/request.ts";
import type {
    AddOrEditOrDelResp,
    AddAndEditCoach,
    GetCoachResp,
    PageCoach,
    PageResp,
    ExistsCoachResp
} from "@/type/coach.ts";

enum API {
    GET_PAGE_COACHES_URL = '/admin/coach/page',   // get
    GET_A_SINGLE_COACH = '/admin/coach/',   // /coach/:id get
    CREATE_A_NEW_COACH = '/admin/coach',    // post
    UPDATE_COACH_INFORMATION = '/admin/coach', // /coach/:id put
    DELETE_COACH = '/admin/coach/', // /coach/:id delete
    CHECK_COACH_EXISTS = '/admin/coach/exists/'
}

// 分页获取教练
export const getPageCoaches = (pageData: PageCoach) => adminRequest.get<any, PageResp>(API.GET_PAGE_COACHES_URL, {params: pageData})

// 获取单个教练
export const getCoachById = (coachId: number) => adminRequest.get<any, GetCoachResp>(`${API.GET_A_SINGLE_COACH}${coachId}`)

// 创建新教练
export const createCoach = (coach: Omit<AddAndEditCoach, 'coachId'>) => adminRequest.post<any, AddOrEditOrDelResp>(API.CREATE_A_NEW_COACH, coach)

// 更新教练信息
export const updateCoach = (coach: AddAndEditCoach) => adminRequest.put<any, AddOrEditOrDelResp>(API.UPDATE_COACH_INFORMATION, coach)

// 删除教练
export const deleteCoach = (coachId: number) => adminRequest.delete<any, AddOrEditOrDelResp>(`${API.DELETE_COACH}${coachId}`)

// 检查教练是否存在
export const checkCoachExists = (coachId: number) => adminRequest.get<any, ExistsCoachResp>(`${API.CHECK_COACH_EXISTS}${coachId}`)


// 客户端
enum MEMBER_API {
    GET_PAGE_COACHES_URL = '/member/coach/page',
    GET_A_SINGLE_COACH = '/member/coach/'
}

// 分页获取教练
export const memberGetPageCoaches = (pageData: PageCoach) => userRequest.get<any, PageResp>(MEMBER_API.GET_PAGE_COACHES_URL, {params: pageData})

export const memberGetCoachById = (coachId: number) => userRequest.get<any, GetCoachResp>(`${MEMBER_API.GET_A_SINGLE_COACH}${coachId}`)
